<template>
  <div class="app-container">
    <div class="clearfix">
      <el-button class="fl" type='primary' @click='linkToAddPublic'>添加更新信息</el-button>
      <div class="fr">
        <el-form>
         <el-input @keyup.enter.native="toSearch" v-model='listQuery.searchName' clearable placeholder='请输入标题' style='width: 250px;'></el-input>
           <el-date-picker
             format='yyyy-MM-dd'
            v-model="listQuery.startTime"
            type="date"
            placeholder="选择日期(开始)">
          </el-date-picker>
          <el-date-picker
            format='yyyy-MM-dd'
            v-model="listQuery.endTime"
            type="date"
            placeholder="选择日期(结束)">
          </el-date-picker>
          <el-button class="search" type='success' icon='el-icon-search' @click="toSearch">搜索</el-button>
        </el-form>
      </div>
    </div>
    <el-table v-loading="listLoading" :data="systemUpdateList" row-key="id" fit highlight-current-row
              style="width: 100%;font-size: 12px;">
      <el-table-column label="标题"
                       class="table c-width100 color-222 family-PingFangSC-Regular font-s12"
                       :header-row-style="{'font-family': 'PingFangSC-Semibold','backgroundColor': '#f5f7fa','color':'#5c6065'}">
        <template slot-scope="scope">
          <div>{{scope.row.title}}</div>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="时间">
        <template slot-scope="scope">
          <span>{{scope.row.createdAt}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="操作">
        <template slot-scope="scope">
          <b @click="linkToUpdateDetail(scope.row.uiId)">编辑</b><span class="color-409">|</span>
          <b @click="delUpdate(scope.row.uiId)">删除</b>
        </template>
      </el-table-column>
    </el-table>
    <div class="block text-c">
				<!--分页组件 current-page:当前页   -->
				<!--   page-sizes:每页几条数据（选项）   -->
				<!--   page-size:每页几条数据   -->
				<!--   total:总条数   -->
			    <el-pagination
			      @size-change="handleSizeChange"
			      @current-change="handleCurrentChange"
			      :current-page="listQuery.currentPage"
			      :page-sizes="[10, 20, 30, 40, 50]"
			      :page-size="10"
			      layout="total, sizes, prev, pager, next, jumper"
			      :total="listQuery.total">
			    </el-pagination>
			</div>
  </div>
</template>
<script>
import { toGetUpdateList, toDelUpdate } from '@/api/extra'
export default {
  data() {
    return {
      listLoading: false,
      listQuery: {
        searchName: '',
        startTime: '',
        endTime: '',
        total: 10
      },
      systemUpdateList: []

    }
  },
  created() {
    this.getUpdateList()
  },
  methods: {
    getUpdateList() {
      this.listLoading = true
      toGetUpdateList(this.listQuery).then(res => {
        this.systemUpdateList = res.data.data.data
        this.listQuery.total = res.data.data.total
        this.listLoading = false
      })
        .catch(err => {
          console.log(err)
        })
    },
    handleSizeChange(val) { // 切换每页几条数据方法
      this.listQuery.limit = val
      this.getUpdateList()
    },
    handleCurrentChange(val) { // 切换当前页
      this.listQuery.page = val
      this.getUpdateList()
    },
    linkToAddPublic() {
      this.$router.push({ path: `/systemUpdates/addUpdate` })
    },
    toSearch() {
      this.listQuery.page = 1
      this.getUpdateList()
    },
    linkToUpdateDetail(id) {
      this.$router.push({ path: `/systemUpdates/editUpdate/${id}` })
    },
    delUpdate(id) {
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        toDelUpdate(id).then(res => {
        // 正确回调
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getUpdateList()
        })
          .catch(err => {
            console.log(err)
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>
<style>

</style>
